﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;

/// <summary>
/// Summary description for D_Registration
/// </summary>
namespace Bestlife.ERP.DataAccess
{
    public class D_Registration
    {
        public D_Registration()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public static int addDistributor(Bestlife.ERP.Entities.E_Registration reg)
        {
            SqlConnection conn_new = new SqlConnection();
            int status = 0;
            try
            {
                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);
      
                //  String Ssql = "INSERT INTO Tbl_Distributor(Dis_ID,Sup_ID,Title,Giv_Name,Sur_Name,Che_Name,Address1,Address2,City,Province,Zip_Code,Hom_Tel_No,Mob_No,Email,Occupation,Bussiness_NameAdd,Office_Tel,ID_No,Valid_Id_Type,Nationality,Dob,Beneficiary,Ben_ID_Type,Ben_ID_No,Ben_Rel,Ben_Add1,Ben_Add2,Ben_City,Ben_Province,Ben_Zip_Code,Answer,Sec_Word,Qa_Pin,Pas_Word,Web_Url,Ship_Contact,Ship_Address1,Ship_Address2,Ship_City,Ship_Province,Ship_Zip_Code,Ship_Hom_Tel_No,Ship_Mob_No,Ship_Email)VALUES('" + reg.Dis_Id1 + "','" + reg.Sup_ID1 + "','" + reg.Title1 + "','" + reg.Giv_Name1 + "','" + reg.Sur_Name1 + "','" + reg.Che_Name1 + "','" + reg.Address11 + "','" + reg.Address21 + "','" + reg.City1 + "','" + reg.Province1 + "','" + reg.Zip_Code1 + "','" + reg.Home_Tel_No1 + "','" + reg.Mob_No1 + "','" + reg.Email1 + "','" + reg.Occupation1 + "','" + reg.Business_NameAdd1 + "','" + reg.Office_Tel1 + "','" + reg.Valid_Id1 + "','" + reg.Valid_ID_Type1 + "','" + reg.Nationality1 + "','" + reg.Dob1 + "','" + reg.Beneficiary1 + "','" + reg.Ben_ID_Type1 + "','" + reg.Ben_ID_No1 + "','" + reg.Ben_Rel1 + "','" + reg.Ben_Add1 + "','" + reg.Ben_Add21 + "','" + reg.Ben_Town1 + "','" + reg.Ben_State1 + "','" + reg.Ben_Zip_Code1 + "','" + reg.Answer1 + "','" + reg.Sec_Word1 + "','" + reg.Qa_Pin1 + "','" + reg.Pas_Word1 + "','" + reg.Web_Url1 + "','" + reg.Ship_Contact1 + "','" + reg.Ship_Address11 + "','" + reg.Ship_Address21 + "','" + reg.Ship_City1 + "','" + reg.Ship_Province1 + "','" + reg.Ship_Zip_Code1 + "','" + reg.Ship_Hom_Tel_No1 + "','" + reg.Ship_Mob_No1 + "','" + reg.Ship_Email1 + "')";

                String Ssql = "INSERT INTO Tbl_Distributor(Dis_ID,Sup_ID,Title,Giv_Name,Sur_Name,Che_Name,Address1,Address2,City,Province,Zip_Code,Hom_Tel_No,Mob_No,Email,Occupation,Bussiness_NameAdd,Office_Tel,ID_No,Valid_Id_Type,Nationality,Dob,Beneficiary,Ben_ID_Type,Ben_ID_No,Ben_Rel,Ben_Add1,Ben_Add2,Ben_City,Ben_Province,Ben_Zip_Code,Answer,Sec_Word,Qa_Pin,Pas_Word,Web_Url,Ship_Contact,Ship_Address1,Ship_Address2,Ship_City,Ship_Province,Ship_Zip_Code,Ship_Hom_Tel_No,Ship_Mob_No,Ship_Email,Dplan)VALUES('" + reg.Dis_Id1 + "','" + reg.Sup_ID1 + "','" + reg.Title1 + "','" + reg.Giv_Name1 + "','" + reg.Sur_Name1 + "','" + reg.Che_Name1 + "','" + reg.Address11 + "','" + reg.Address21 + "','" + reg.City1 + "','" + reg.Province1 + "','" + reg.Zip_Code1 + "','" + reg.Home_Tel_No1 + "','" + reg.Mob_No1 + "','" + reg.Email1 + "','" + reg.Occupation1 + "','" + reg.Business_NameAdd1 + "','" + reg.Office_Tel1 + "','" + reg.Valid_Id1 + "','" + reg.Valid_ID_Type1 + "','" + reg.Nationality1 + "','" + reg.Dob1 + "','" + reg.Beneficiary1 + "','" + reg.Ben_ID_Type1 + "','" + reg.Ben_ID_No1 + "','" + reg.Ben_Rel1 + "','" + reg.Ben_Add1 + "','" + reg.Ben_Add21 + "','" + reg.Ben_Town1 + "','" + reg.Ben_State1 + "','" + reg.Ben_Zip_Code1 + "','" + reg.Answer1 + "','" + reg.Sec_Word1 + "','" + reg.Qa_Pin1 + "','" + reg.Pas_Word1 + "','" + reg.Web_Url1 + "','" + reg.Ship_Contact1 + "','" + reg.Ship_Address11 + "','" + reg.Ship_Address21 + "','" + reg.Ship_City1 + "','" + reg.Ship_Province1 + "','" + reg.Ship_Zip_Code1 + "','" + reg.Ship_Hom_Tel_No1 + "','" + reg.Ship_Mob_No1 + "','" + reg.Ship_Email1 + "','C')";
                Boolean exec = Bestlife.ERP.DataAccess.clsCon.AddEditDel(Ssql);

                // ENTERING PLACEMENT DATA TO CROWN DATABASE

                String crownplacement = "INSERT INTO [BestlifeDB].[dbo].[Tbl_Placement](Sup_ID,Agent_ID,APIN,Group_ID,Dis_ID)VALUES('"+reg.Sup_ID1+"','"+reg.Agent_id1+"','"+reg.APIN1+"','"+reg.Team1+"','"+reg.Dis_Id1+"')";
                Boolean done = Bestlife.ERP.DataAccess.clsCon.AddEditDel(crownplacement);

                // ENTERING DATA TO PHP DATABASE dealerdetails

                int dealercode = int.Parse(reg.Dis_Id1.ToString());
                String sql = "INSERT INTO [bestlife_php].[dbo].[dealer] (dealercode,nameinfull,firstname,address1,address2,country,idno,telhome1,email,birthday,reletionship)VALUES('" +dealercode+ "','" + reg.Giv_Name1 + "','" + reg.Giv_Name1 + "','"+reg.Address11+"','"+reg.Address21+"','"+reg.Country1+"','"+reg.Valid_Id1+"','"+reg.Home_Tel_No1+"','"+reg.Email1+"','"+reg.Dob1+"','"+reg.Ben_Rel1+"')";
                Boolean exe = Bestlife.ERP.DataAccess.clsCon.AddEditDel(sql);

                // ENTERING DATA TO PHP DATABASE dealerplacement

                int apin = int.Parse(reg.APIN1);
                int groupid = reg.Team1;
                int introducercode = int.Parse(reg.Sup_ID1);
                String placement ="INSERT INTO [bestlife_php].[dbo].[dealerplacement] (apin,dealercode,groupid,introducercode)VALUES('"+apin+"','"+dealercode+"','"+groupid+"','"+introducercode+"')";
                Boolean placex = Bestlife.ERP.DataAccess.clsCon.AddEditDel(placement);

                clsCon.conn_new.Close();

            }
            catch (Exception)
            {
                // Console.WriteLine(exx);
            }
            return status;
        }

        public static int addBonusDetails(Bestlife.ERP.Entities.E_Registration reg)
        {
            SqlConnection conn_new = new SqlConnection();
            int status = 0;
            try
            {
                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);

                String Ssql = "INSERT INTO Bonus(User_id,Tpv,ppv,Cpv,CPV_month,tppv_month,T_sales,T_commision,T_Lship,Bv,user_Status,Lship_Status,Tbv,tbv_month,User_Create,Date_Create,Last_Modify,Store_pv,Store_bv,Store_comm,Store_Lship)VALUES('" + reg.Dis_Id1 + "','0','0','0','0','0','0','0','0','0','0','0','0','0','"+reg.Giv_Name1+"','"+DateTime.Now+"','"+DateTime.Now+"','0','0','0','0')";
                Boolean exec = Bestlife.ERP.DataAccess.clsCon.AddEditDel(Ssql);
                clsCon.conn_new.Close();
            }
            catch (Exception)
            {
                // Console.WriteLine(exx);
            }
            return status;
        }

        //public static int addplacement(Bestlife.ERP.Entities.E_Registration reg)
        //{
        //    SqlConnection conn_new = new SqlConnection();
        //    int status = 0;
        //    try
        //    {
        //        String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
        //        Bestlife.ERP.DataAccess.clsCon.connect(connStr);

        //        String Ssql = "INSERT INTO Bonus(User_id,Tpv,ppv,Cpv,CPV_month,tppv_month,T_sales,T_commision,T_Lship,Bv,user_Status,Lship_Status,Tbv,tbv_month,User_Create,Date_Create,Last_Modify,Store_pv,Store_bv,Store_comm,Store_Lship)VALUES('" + reg.Dis_Id1 + "','0','0','0','0','0','0','0','0','0','0','0','0','0','" + reg.Giv_Name1 + "','" + DateTime.Now + "','" + DateTime.Now + "','0','0','0','0')";
        //        Boolean exec = Bestlife.ERP.DataAccess.clsCon.AddEditDel(Ssql);
        //        clsCon.conn_new.Close();
        //    }
        //    catch (Exception)
        //    {
        //        // Console.WriteLine(exx);
        //    }
        //    return status;
        //}
    }
}